package fr.afcepf.atod18.hotels.managedbeans;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import fr.afcepf.atod18.hotels.entities.Occupationchambre;
import fr.afcepf.atod18.hotels.entities.OccupationchambreId;
import fr.afcepf.atod18.hotels.entities.Reservationchambre;

public class UI_BasketReservation {
	private String headername;
	private String dateDebut;
	private String dateFin;
	private String hotelname;
	@SuppressWarnings("unused")
	private String chambrenumero;
	private Reservationchambre ch;
	private double price = 0.0;
	private double total;
	private List<UI_BasketOption> listOptions;
	SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

	public UI_BasketReservation() {
		listOptions = new ArrayList<UI_BasketOption>();
	}

	public Reservationchambre getCh() {
		return ch;
	}

	public void setCh(Reservationchambre ch) {
		this.ch = ch;
	}

	public String getHeadername() {
		headername = "Reservation Chambre";
		return headername;
	}

	public void setHeadername(String headername) {
		this.headername = headername;
	}

	public String getPrice() {
		return Double.toString(price);
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getDateDebut() {
		dateDebut = sdf.format( ch.getId().getDateDebut() );
		return dateDebut;
	}

	public void setDateDebut(String dateDebut) {
		this.dateDebut = dateDebut;
	}

	public String getDateFin() {
		dateFin = sdf.format( ch.getId().getDateFin() ) ;
		return dateFin;
	}

	public void setDateFin(String dateFin) {
		this.dateFin = dateFin;
	}

	public String getHotelname() {
		return hotelname;
	}

	public void setHotelname(String hotelname) {
		this.hotelname = hotelname;
	}

	public String getChambrenumero() {
		return Integer.toString(ch.getId().getChambreNumero());
	}

	public void setChambrenumero(String chambrenumero) {
		this.chambrenumero = chambrenumero;
	}

	public double getTotal() {
		Calendar cal= Calendar.getInstance();
		cal.setTime(ch.getId().getDateFin());
		Date endDate = cal.getTime();
		cal.setTime(ch.getId().getDateDebut());
		Date currentDate = cal.getTime();
		int nbr_days = 0;
		while( currentDate.compareTo(endDate) != 0  ) {
            nbr_days = nbr_days + 1;
			cal.add(Calendar.DAY_OF_MONTH, 1);
			currentDate = cal.getTime();
		}
		total = price * nbr_days;
		for ( UI_BasketOption bo:listOptions) {
			total = total + bo.getTotal();
		}
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public List<UI_BasketOption> getListOptions() {
		return listOptions;
	}

	public void setListOptions(List<UI_BasketOption> listOptions) {
		this.listOptions = listOptions;
	}

}
